package ch.msoftch.gui.utils.popup.actions;

import org.eclipse.core.resources.*;
import org.eclipse.jface.action.*;
import org.eclipse.jface.viewers.*;
import org.eclipse.ui.*;
import org.eclipse.ui.part.*;
import ch.msoftch.gui.utils.*;

/**
 * Action used to create a property class.<br>
 * This version is for the text editor.
 * 
 * @author hautle
 */
public class CreateI18NEditorAction implements IEditorActionDelegate {
    /** The editor. */
    private IEditorPart editor;

    /**
     * {@inheritDoc}
     */
    @Override
    public void setActiveEditor(IAction action, IEditorPart targetEditor) {
        editor = targetEditor;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void run(IAction action) {
        final IFile file = ((FileEditorInput) editor.getEditorInput()).getFile();
        try {
            PropertyClassBuilder.create(file);
        } catch (Exception e) {
            EclipseHelper.showError(editor.getSite().getShell(), "Error while generating the class", e);
        }
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void selectionChanged(IAction action, ISelection selection) {
    }
}
